<!--
 * @Description: 文件库（文件管理）
 * @Author: HuiSir<https://gitee.com/huisir001>
 * @Date: 2025-08-04 11:35:42
 * @LastEditTime: 2025-09-16 17:36:29
-->
<template>
  <TablePage
    v-model:cols="tableCols"
    v-model:toolsOptions="toolsOptions"
    v-model:rowBtnsOptions="rowBtnsOptions"
    :listRequest="getFileListByPage"
  >
    <template #rowBtnsLeft="scope">
      <!-- 使用自定义复制指令 -->
      <el-button link size="small" type="primary" v-copy="scope.row.url">
        <fy-icon name="CopyDocument" size="13" />
        复制URL
      </el-button>
    </template>
  </TablePage>
</template>

<script lang="ts" setup>
import useTableCols from "./hooks/useTableCols";
import useToolsOptions from "./hooks/useToolsOptions";
import useRowBtnsOptions from "./hooks/useRowBtnsOptions";
import TablePage from "@/components/TablePage/index.vue";
import { IFormOption } from "@/ui";
import { getFileListByPage, getFileGroupList } from "@/api/file/index";

// 配置项
defineOptions({ name: "FileLibrary", isFull: true });

// 分类列表
const getGroupOptions = async (formOptions: IFormOption[]) => {
  const res = await getFileGroupList();
  const groupInd = formOptions.findIndex((opt) => opt.key === "group");
  formOptions[groupInd].options = res.data.map(
    (item: { name: string; id: string }) => ({
      label: item.name,
      value: item.name,
    })
  );
};

// 文件选择后不会默认上传，待新增保存时才会上传
// 删除后，相应文件也会删除
// 编辑时不可重新选择文件，若预上传新文件请删除该条后再新增，避免无法删除文件而造成冗余

// 表格配置
const tableCols = useTableCols();
const rowBtnsOptions = useRowBtnsOptions(getGroupOptions);
const toolsOptions = useToolsOptions(getGroupOptions);
</script>
